<?php
class myThumbnail
{
  public static function thumbnails($filename, $object, $user)
  {
        foreach(sfConfig::get('app_image_sizes') as $type => $sizes)
        {
          $destination = implode(DIRECTORY_SEPARATOR, array(sfConfig::get('sf_upload_dir'), $user->getUsername(), $type, $filename));
          //$filename = sha1($file->getOriginalName()).$file->getExtension($file->getOriginalExtension());          
          //myThumbnail::thumbnail($sizes, $file->getTempName(), $destination);
          
          $info = getimagesize($object->getFile());
          $width = $info[0];
          $height = $info[1];
          
          //$thumb = new sfThumbnail($sizes['w'], $sizes['h']);
          
          if (($width > $height) and ($sizes['w'] <= $sizes['h']))
          {          	
            $thumb = new sfThumbnail(9999999, $sizes['h']);          	
          }
          else
          {
            $thumb = new sfThumbnail($sizes['w'], 9999999);
          }
          
          $thumb->loadFile($object->getFile());
          
          if ($sizes['h'])
          {
            $thumb->crop($sizes['w'], $sizes['h']);
          }
          
          
          if ($sizes['wm'])
          {
            $size = 10;
            $angle = 90;
            $font = sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'jesaya free.ttf';
            $text = sfConfig::get('app_site_name').' © '.$user->getName();
            $thumb->addWatermark($size, $angle, $font, $text);
          }
          
          $thumb->save($destination, 'image/jpeg');
          $thumb->freeAll();
        }
        
        return true;
  }
}